package gogogo.liwushuo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import gogogo.liwushuo.R;
import gogogo.liwushuo.bean.HotFragmentBean;
import gogogo.liwushuo.fragment.HotFragment.CommenFragment;
import gogogo.liwushuo.fragment.HotFragment.DetailFragment;
import gogogo.liwushuo.fragment.HotFragment.GoodsFragment;

/**
 * author: John
 * time: 2016/7/22
 * overview:热门详情页面分为2种
 * usage:
 */
public class DetailActivity extends AppCompatActivity {
    @InjectView(R.id.hot_detail_tab)
    TabLayout hotDetailTab;
    @InjectView(R.id.hot_detail_vp)
    ViewPager hotDetailVp;
    private String[] mTabTitle={"单品","详情","评论"};
    private List<Fragment> mFragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hot_detail);
        ButterKnife.inject(this);
        initData();
    }

    private void initData() {
        mFragments=new ArrayList<>();
        mFragments.add(new GoodsFragment());
        mFragments.add(new DetailFragment());
        mFragments.add(new CommenFragment());
//        mFragments.add(GoodsFragment.newInstance(mDatas));
        hotDetailVp.setAdapter(new HotPagerAdapter(getSupportFragmentManager()));
        hotDetailTab.setupWithViewPager(hotDetailVp);
        for (int i = 0; i < hotDetailTab.getTabCount(); i++) {
            TabLayout.Tab tab = hotDetailTab.getTabAt(i);
            tab.setText(mTabTitle[i]);
        }
    }


    private class HotPagerAdapter extends FragmentPagerAdapter {

        public HotPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }
    }
}
